package com.atlin.project.model.enums.chart;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 图表类型枚举
 */
public enum ChartTypeEnum {

    LINE("折线图", "line"),
    BAR("柱状图", "bar"),
    PIE("饼图", "pie"),
    SCATTER("散点图", "scatter"),
    HISTOGRAM("直方图", "histogram"),
    BOX("箱线图", "box"),
    AREA("面积图", "area"),
    BUBBLE("气泡图", "bubble"),
    RADAR("雷达图", "radar"),
    HEATMAP("热力图", "heatmap");

    private final String text;

    private final String value;

    ChartTypeEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static ChartTypeEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (ChartTypeEnum anEnum : ChartTypeEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }
}
